//
//  ConduitCell.m
//  CarWorld
//
//  Created by 曹杨杨 on 15/3/30.
//  Copyright (c) 2015年 CarWorldTeam. All rights reserved.
//

#import "ConduitCell.h"

@implementation ConduitCell

- (void)dealloc
{
    [_image_View release];
    [_titleLabel release];
    [_timeLabel release];
    [_cellData release];
    [super dealloc];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    return [self initWithStyle:style reuseIdentifier:reuseIdentifier height:0];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier height:(CGFloat)height
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGRect rect = [UIScreen mainScreen].bounds;
        CGFloat imageViewWidth = (rect.size.width - 20)*0.3;
        CGFloat picHeight = height - 20;
        _image_View = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, imageViewWidth, picHeight)];
        [self.contentView addSubview:_image_View];
        
        CGFloat width = rect.size.width - imageViewWidth - 10;
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10+5+imageViewWidth, 12, width-10, (picHeight -5)/2+10)];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.numberOfLines  = 0;
        [self.contentView addSubview:_titleLabel];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10+5+imageViewWidth, 15+5+(picHeight -5)/2, width, (picHeight -5)/2)];
        _timeLabel.font = [UIFont systemFontOfSize:13];
        //        _titleLabel.attributedText = [_timeLabel.text tintColor:[UIColor redColor] subString:_timeLabel.text];
        _timeLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_timeLabel];
    }
    return self;
}

- (void)setCellData:(ConduitListData *)cellData
{
    if (_cellData != cellData) {
        [_cellData release];
        _cellData = [cellData retain];
        _titleLabel.text = cellData.title;
        _timeLabel.text = [NSString stringWithFormat:@"%@",[cellData.createTime substringToIndex:10]];
        if (_cellData.image == nil) {
            
        }else{
            _image_View.image = self.cellData.image;
        }
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
